﻿// -------------------------------------------------------------------------
//    @FileName         :    NFHeroUtil.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-30
//    @Email            :    445267987@qq.com
//    @Module           :    NFHeroUtil
//
// -------------------------------------------------------------------------

#include "NFHeroUtil.h"

#include <E_Actor.nanopb.h>
#include <DescStore/SkinSkinDesc.h>
#include "ConstantDescEx.h"
#include "proto_common_hero.nanopb.h"

int NFHeroUtil::InitHero(HeroOne &hero_one_mem, const E_Actor *pHeroDesc)
{
    hero_one_mem.id = pHeroDesc->id;
    hero_one_mem.job = pHeroDesc->job;

    InitHeroGemstone(&hero_one_mem.gemstone_data, pHeroDesc);

    hero_one_mem.equip_list_count = ARRAYSIZE(hero_one_mem.equip_list);
    hero_one_mem.buff_equip_list_count = ARRAYSIZE(hero_one_mem.buff_equip_list);
    hero_one_mem.temp_attr_list_count = ARRAYSIZE(hero_one_mem.temp_attr_list);

    // Default Skin:
    std::vector<const E_SkinSkin *> vecSkin = SkinSkinDesc::Instance()->GetDescByHeroIdDefaultSkin(pHeroDesc->id, 1);
    if (vecSkin.size() > 0 && vecSkin[0])
    {
        hero_one_mem.skin_desc = vecSkin[0]->id;
    }
    else
    {
        LOG_ERR(hero_one_mem.id, -1, "hero no any default skin:{} ", pHeroDesc->id);
    }

    hero_one_mem.hero_rank = 0;
    hero_one_mem.hero_sub_rank = 0;

    return 0;
}

int NFHeroUtil::InitHeroGemstone(GemStoneData *pGemstoneData, const E_Actor *pHeroDesc)
{
    CHECK_NULL(0, pGemstoneData);

    pGemstoneData->wear_data_count = ARRAYSIZE(pGemstoneData->wear_data);
    for (int i = 0; i < (int)pGemstoneData->wear_data_count; ++i)
    {
        pGemstoneData->wear_data[i].gemstone_count = ARRAYSIZE(pGemstoneData->wear_data[i].gemstone);
    }

    return 0;
}

int NFHeroUtil::InitHpMp(HeroOne& stHeroOut)
{
    stHeroOut.attr_list[proto_ff::EN_ATTR_HP_RESERVE].value = ConstantDescEx::Instance()->GetValue(proto_ff::EN_CONST_INIT_HP_RESERVE);
    stHeroOut.attr_list[proto_ff::EN_ATTR_MP_RESERVE].value = ConstantDescEx::Instance()->GetValue(proto_ff::EN_CONST_INIT_MP_RESERVE);
    stHeroOut.attr_list[proto_ff::EN_ATTR_HP].value = stHeroOut.attr_list[proto_ff::EN_ATTR_MAX_HP].value;
    stHeroOut.attr_list[proto_ff::EN_ATTR_MP].value = stHeroOut.attr_list[proto_ff::EN_ATTR_MAX_MP].value;

    return 0;
}
